<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="林湃滨的个人博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Mysql事务隔离级别和MVCC |  滨书
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="滨书" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-数据库/Mysql事务隔离级别和MVCC" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Mysql事务隔离级别和MVCC
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/01/03/%E6%95%B0%E6%8D%AE%E5%BA%93/Mysql%E4%BA%8B%E5%8A%A1%E9%9A%94%E7%A6%BB%E7%BA%A7%E5%88%AB%E5%92%8CMVCC/" class="article-date">
  <time datetime="2020-01-03T12:32:13.000Z" itemprop="datePublished">2020-01-03</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.9k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">7分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <p>[toc]</p>
<h1 id="Mysql的事务隔离级别"><a href="#Mysql的事务隔离级别" class="headerlink" title="Mysql的事务隔离级别"></a>Mysql的事务隔离级别</h1><p>准备工作：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 事先准备一个基本表</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t (</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">INT</span> PRIMARY <span class="keyword">KEY</span>,</span><br><span class="line">    c <span class="built_in">VARCHAR</span>(<span class="number">100</span>)</span><br><span class="line">) <span class="keyword">Engine</span>=<span class="keyword">InnoDB</span> <span class="keyword">CHARSET</span>=utf8; </span><br><span class="line"></span><br><span class="line"><span class="comment">-- 准备一条数据</span></span><br><span class="line"> <span class="keyword">INSERT</span> <span class="keyword">INTO</span> t <span class="keyword">VALUES</span>(<span class="number">1</span>, <span class="string">'刘备'</span>);</span><br></pre></td></tr></table></figure>



<blockquote>
<p>效果：</p>
<p> mysql&gt; SELECT * FROM t;<br>+—-+——–+<br>| id | c      |<br>+—-+——–+<br>|  1 | 刘备   |<br>+—-+——–+<br>1 row <strong>in</strong> set (0.01 sec) </p>
</blockquote>
<h2 id="（一）为什么存在多种隔离级别"><a href="#（一）为什么存在多种隔离级别" class="headerlink" title="（一）为什么存在多种隔离级别"></a>（一）为什么存在多种隔离级别</h2><p>如Mysql一般，数据库软件是一个Server/Client（服务器/客户端）架构的软件。</p>
<p>对于同一个服务器来说，可以有若干个客户端与之连接，每个客户端与服务器建立连接之后，我们称该连接为<strong>一个会话</strong>（Session）。我们可以同时在不同的会话中输入各种语句，这些语句可以作为事务的一部分进行处理。不同的会话可以同时发送请求，也就是说服务器可能同时在处理多个事务，这样子就会导致不同的事务可能同时访问到相同的记录。</p>
<p>事务有一个特性：事务的执行结果对其他事务的执行不会造成影响，我们称之为<code>隔离性</code>，理论上在某个事务对某个数据进行访问时，其他事务应该进行排队，当该事务提交之后，其他事务才可以继续访问这个数据。但是这样子的话对性能影响太大，所以设计数据库的大叔提出了各种<code>隔离级别</code>，来最大限度的提升系统并发处理事务的能力，但是这也是以牺牲一定的<code>隔离性</code>来达到的。 </p>
<h2 id="（二）各种隔离级别"><a href="#（二）各种隔离级别" class="headerlink" title="（二）各种隔离级别"></a>（二）各种隔离级别</h2><h3 id="1、未提交读（Read-Uncommitted）"><a href="#1、未提交读（Read-Uncommitted）" class="headerlink" title="1、未提交读（Read Uncommitted）"></a>1、未提交读（Read Uncommitted）</h3><p>如果一个事务读到了另一个未提交事务修改过的数据，那么这种<code>隔离级别</code>就称之为<code>未提交读</code>（英文名：<code>READ UNCOMMITTED</code>），示意图如下：</p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>Begin；</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br>（此时读到的数据为’关羽’。）</td>
<td></td>
</tr>
</tbody></table>
<p>如上图，<code>Session A</code>和<code>Session B</code>各开启了一个事务，<code>Session B</code>中的事务先将<code>id</code>为<code>1</code>的记录的列<code>c</code>更新为<code>&#39;关羽&#39;</code>，然后<code>Session A</code>中的事务再去查询这条<code>id</code>为<code>1</code>的记录，那么在<code>未提交读</code>的隔离级别下，查询结果就是<code>&#39;关羽&#39;</code>，也就是说某个事务读到了另一个未提交事务修改过的记录。但是如果<code>Session B</code>中的事务稍后进行了回滚，那么<code>Session A</code>中的事务相当于读到了一个不存在的数据，这种现象就称之为<code>脏读</code>，就像这个样子：</p>
<p><img src="https://mmbiz.qpic.cn/mmbiz_png/RLmbWWew55GdJzrqhNibDpUmiarhibQOzyxZ3qBgyBGS5wkxzMUPSjLKUpzkKzJunBEMe1sJoA2OjJnJapx1mfIXw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" alt="img"></p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>Begin；</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br>（此时读到的数据为’关羽’。）</td>
<td></td>
</tr>
</tbody></table>
<p><code>脏读</code>违背了现实世界的业务含义，所以这种<code>READ UNCOMMITTED</code>算是十分不安全的一种<code>隔离级别</code>。</p>
<h3 id="2、提交读（Read-Committed）"><a href="#2、提交读（Read-Committed）" class="headerlink" title="2、提交读（Read Committed）"></a>2、提交读（Read Committed）</h3><p>如果一个事务只能读到另一个已经提交的事务修改过的数据，并且其他事务每对该数据进行一次修改并提交后，该事务都能查询得到最新值，那么这种<code>隔离级别</code>就称之为<code>已提交读</code>（英文名：<code>READ COMMITTED</code>），如图所示：</p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>Begin；</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’刘备’。）</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>COMMIT;</td>
</tr>
<tr>
<td>6</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’关羽’。）</td>
<td></td>
</tr>
</tbody></table>
<p>从图中可以看到，第4步时，由于<code>Session B</code>中的事务尚未提交，所以<code>Session A</code>中的事务查询得到的结果只是<code>&#39;刘备&#39;</code>，而第6步时，由于<code>Session B</code>中的事务已经提交，所以<code>Session B</code>中的事务查询得到的结果就是<code>&#39;关羽&#39;</code>了。</p>
<p>对于某个处在在<code>已提交读</code>隔离级别下的事务来说，只要其他事务修改了某个数据的值，并且之后提交了，那么该事务就会读到该数据的最新值，比方说：</p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’刘备’。）</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；（隐式提交）</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’关羽’。）</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>UPDATE t SET c =’张飞’ WHERE id=1；（隐式提交）</td>
</tr>
<tr>
<td>6</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’张飞’。）</td>
<td></td>
</tr>
</tbody></table>
<p>我们在<code>Session B</code>中提交了几个隐式事务，这些事务都修改了<code>id</code>为<code>1</code>的记录的列c的值，每次事务提交之后，<code>Session A</code>中的事务都可以查看到最新的值。这种现象也被称之为<code>不可重复读</code>。</p>
<h3 id="3、可重复读（Repeatable-Read）"><a href="#3、可重复读（Repeatable-Read）" class="headerlink" title="3、可重复读（Repeatable Read）"></a>3、可重复读（Repeatable Read）</h3><p>在一些业务场景中，一个事务只能读到另一个已经提交的事务修改过的数据，但是第一次读过某条记录后，即使其他事务修改了该记录的值并且提交，该事务之后再读该条记录时，读到的仍是第一次读到的值，而不是每次都读到不同的数据。那么这种<code>隔离级别</code>就称之为<code>可重复读</code>（英文名：<code>REPEATABLE READ</code>），如图所示：</p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’刘备’。）</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；（隐式提交）</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’刘备’。）</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>UPDATE t SET c =’张飞’ WHERE id=1；（隐式提交）</td>
</tr>
<tr>
<td>6</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’刘备’。）</td>
<td></td>
</tr>
</tbody></table>
<p>从图中可以看出来，<code>Session A</code>中的事务在第一次读取<code>id</code>为<code>1</code>的记录时，列<code>c</code>的值为<code>&#39;刘备&#39;</code>，之后虽然<code>Session B</code>中隐式提交了多个事务，每个事务都修改了这条记录，但是<code>Session A</code>中的事务读到的列<code>c</code>的值仍为<code>&#39;刘备&#39;</code>，与第一次读取的值是相同的。</p>
<h3 id="4、串行化读（Serializable）"><a href="#4、串行化读（Serializable）" class="headerlink" title="4、串行化读（Serializable）"></a>4、串行化读（Serializable）</h3><p>以上3种隔离级别都允许对同一条记录进行<code>读-读</code>、<code>读-写</code>、<code>写-读</code>的并发操作，如果我们不允许<code>读-写</code>、<code>写-读</code>的并发操作，可以使用<code>SERIALIZABLE</code>隔离级别，示意图如下：</p>
<table>
<thead>
<tr>
<th>发生时间编号</th>
<th>Session A</th>
<th>Session B</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Begin；</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>Begin；</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>UPDATE t SET c =’关羽’ WHERE id=1；</td>
</tr>
<tr>
<td>4</td>
<td>SELECT * FROM t WHERE id=1;<br/>（等待ing）</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>COMMIT;</td>
</tr>
<tr>
<td>6</td>
<td>SELECT * FROM t WHERE id=1;<br/>（此时读到的数据为’关羽’。）</td>
<td></td>
</tr>
</tbody></table>
<p>如图所示，当<code>Session B</code>中的事务更新了<code>id</code>为<code>1</code>的记录后，之后<code>Session A</code>中的事务再去访问这条记录时就被卡住了，直到<code>Session B</code>中的事务提交之后，<code>Session A</code>中的事务才可以获取到查询结果。</p>
<p><a href="https://mp.weixin.qq.com/s/SCW_3AypO-rSolMcjCxVtA" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/SCW_3AypO-rSolMcjCxVtA</a></p>
<h1 id="MVCC"><a href="#MVCC" class="headerlink" title="MVCC"></a>MVCC</h1><p>MVCC，全称为： Multi-Version Concurrency Control ，多版本并发控制。</p>
<p>MVCC指的就是在使用<code>READ COMMITTD</code>、<code>REPEATABLE READ</code>这两种隔离级别的事务在执行普通的<code>SEELCT</code>操作时访问记录的版本链的过程，这样子可以使不同事务的<code>读-写</code>、<code>写-读</code>操作并发执行，从而提升系统性能。<code>READ COMMITTD</code>、<code>REPEATABLE READ</code>这两个隔离级别的一个很大不同就是生成<code>ReadView</code>的时机不同，<code>READ COMMITTD</code>在每一次进行普通<code>SELECT</code>操作前都会生成一个<code>ReadView</code>，而<code>REPEATABLE READ</code>只在第一次进行普通<code>SELECT</code>操作前生成一个<code>ReadView</code>，之后的查询操作都重复这个<code>ReadView</code>就好了。 </p>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://linpaibin.gitee.io/2020/01/03/%E6%95%B0%E6%8D%AE%E5%BA%93/Mysql%E4%BA%8B%E5%8A%A1%E9%9A%94%E7%A6%BB%E7%BA%A7%E5%88%AB%E5%92%8CMVCC/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Mysql/" rel="tag">Mysql</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" rel="tag">数据库</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/01/05/%E7%94%9F%E6%B4%BB/%E3%80%90%E6%96%B0%E5%B9%B4%E7%AC%94%E8%AE%B0%E3%80%912020/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            生活笔记【一】
          
        </div>
      </a>
    
    
      <a href="/2020/01/01/InformalEssay/%E3%80%90%E5%B9%B4%E5%BA%A6%E6%80%BB%E7%BB%93%E3%80%912019/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">【年度总结】2019</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        notify: false,
        verify: '',
        app_id: 'gtXNe43HVDH72a7XMn9zNgz8-gzGzoHsz',
        app_key: 'Df8WdcqcC2DCWL1pfcWb4QfN',
        path: window.location.pathname,
        avatar: 'mp',
        placeholder: '既然都来了，便留个爪印呗~_(¦3」∠)_',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2019-2020
        LinPaiBin
      </li>
      <li>
        
          Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar" style="opacity: 0.5;">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="滨书"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E7%94%9F%E6%B4%BB/">生活</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/12/02/AboutMe">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['人生如棋，吾愿为卒','愿你一生努力，一生无憾','不求事事顺意，但求无愧于心'],
    startDelay: 0,
    typeSpeed: 250,
    loop: true,
    backSpeed: 100,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: false
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>




<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>